package com.ocom.devicehttp.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ocom.common.entity.payconfig.EntityDishesInfo;
import com.ocom.common.entity.payconfig.EntityMqttDevice;
import com.ocom.common.request.human.PersonQueryRequest;
import com.ocom.common.request.human.RegisterPalmRequest;
import com.ocom.common.request.payhandle.*;
import com.ocom.common.resp.RespMachMessage;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.JsonResponse;
import com.ocom.common.utils.RandomUtil;
import com.ocom.common.utils.StateCode;
import com.ocom.common.vo.devicehttp.MachMealDataVo;
import com.ocom.devicehttp.feign.machine.HumanClientService;
import com.ocom.devicehttp.feign.machine.PayConfigClientService;
import com.ocom.devicehttp.feign.machine.PayoperFeignService;
import com.ocom.devicehttp.service.TradePayService;
import com.ocom.redis.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;


@Service
public class TradePayServiceImpl implements TradePayService {

    private static Logger log = LoggerFactory.getLogger(TradePayServiceImpl.class);

    @Autowired
    private PayoperFeignService payoperFeignService;

    @Autowired
    private HumanClientService humanClientService;

    @Autowired
    private PayConfigClientService payConfigClientService;

    @Autowired
    private RedisUtil redisUtil;

    /*
     * @Description:支付请求（强在线）
     * @Author: lu 
     * @Date: 2022/4/28 17:03
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse onlinePay(Map<String, Object> map) {
        Integer type= (Integer) map.get("type");
        if (type==5 ||type==10){
            QrCodePayRequest qrCodePayRequest=new QrCodePayRequest();
            try {
                qrCodePayRequest.setMachNo(String.valueOf(map.get("machNo")));
                qrCodePayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                if (map.get("consType") !=null){
                    qrCodePayRequest.setConsType((Integer) map.get("consType"));
                }
                qrCodePayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
                qrCodePayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
                qrCodePayRequest.setAmount((Integer) map.get("amount"));

                try {
                    Object consState = map.get("consState");
                    if (consState != null) {
                        Integer cons = (Integer) consState;
                        qrCodePayRequest.setConsState(cons);
                        if ((cons == 3 || cons == 5 ) && map.get("menuData") != null) {
                            if(map.get("consDate") != null) qrCodePayRequest.setConsDate(String.valueOf(map.get("consDate")));
                            if(map.get("consMeal") != null) qrCodePayRequest.setConsMeal((Integer)map.get("consMeal"));
                            if(map.get("consPoint") != null) qrCodePayRequest.setConsPoint((Integer)map.get("consPoint"));
                            qrCodePayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                        }
                    }
                }catch (Exception exception){
                    log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）订餐1",map.get("machNo"),qrCodePayRequest,exception);
                }

            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）web",map.get("machNo"),qrCodePayRequest,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.qrCodePay(qrCodePayRequest);
            if (result.getCode()==200){
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","支付请求（强在线）web",map.get("machNo"),qrCodePayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else if (type==1 || type==4 || type==7 || type== 8 || type== 9 || type== 21  || type== 25){
            QrCardPayRequest qrCardPayRequest=new QrCardPayRequest();
            try {
                qrCardPayRequest.setMachNo(String.valueOf(map.get("machNo")));
                qrCardPayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                qrCardPayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
                qrCardPayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
                qrCardPayRequest.setAmount((Integer) map.get("amount"));
                if (map.get("consType") !=null){
                    qrCardPayRequest.setConsType((Integer) map.get("consType"));
                }
                if (type == 8){
                    if (map.get("face_token") !=null){
                        qrCardPayRequest.setFaceToken((String) map.get("face_token"));
                    }else{
                        return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
                    }
                }
                if (type == 9){
                    if (map.get("face_token") ==null || map.get("uId") ==null || map.get("verificationData") ==null ){
                        return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
                    }
                    qrCardPayRequest.setFaceToken((String) map.get("face_token"));
                    qrCardPayRequest.setUId((String) map.get("uId"));
                    qrCardPayRequest.setIotSignInfo((String) map.get("verificationData"));
                }
                try {
                    Object consState = map.get("consState");
                    if (consState != null) {
                        Integer cons = (Integer) consState;
                        qrCardPayRequest.setConsState(cons);
                        if ((cons == 3 || cons == 5 ) && map.get("menuData") != null) {
                            if(map.get("consDate") != null) qrCardPayRequest.setConsDate(String.valueOf(map.get("consDate")));
                            if(map.get("consMeal") != null) qrCardPayRequest.setConsMeal((Integer)map.get("consMeal"));
                            if(map.get("consPoint") != null) qrCardPayRequest.setConsPoint((Integer)map.get("consPoint"));
                            qrCardPayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                        }
                    }
                }catch (Exception exception){
                    log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）订餐1",map.get("machNo"),qrCardPayRequest,exception);
                }
                qrCardPayRequest.setType(type);
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）web",map.get("machNo"),qrCardPayRequest,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result = payoperFeignService.getPayCard(qrCardPayRequest);
            if (result.getCode()==200){
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","支付请求（强在线）web",map.get("machNo"),qrCardPayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else if ( type== 20 ){  //20 现金
            CashPayRequest cashPayRequest =new CashPayRequest();
            cashPayRequest.setMachNo(String.valueOf(map.get("machNo")));
            cashPayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
            cashPayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
            cashPayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
            cashPayRequest.setAmount((Integer) map.get("amount"));
            cashPayRequest.setType(type);
            try {
                Object consState = map.get("consState");
                if (consState != null) {
                    Integer cons = (Integer) consState;
                    cashPayRequest.setConsState(cons);
                    if ((cons == 3 || cons == 5 ) && map.get("menuData") != null) {
                        if(map.get("consDate") != null) cashPayRequest.setConsDate(String.valueOf(map.get("consDate")));
                        if(map.get("consMeal") != null) cashPayRequest.setConsMeal((Integer)map.get("consMeal"));
                        if(map.get("consPoint") != null) cashPayRequest.setConsPoint((Integer)map.get("consPoint"));
                        cashPayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                    }
                }
            }catch (Exception exception){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）订餐1",map.get("machNo"),cashPayRequest,exception);
            }
            Result result=payoperFeignService.cashPayDiches(cashPayRequest);
            if (result.getCode()==200){
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","支付请求（强在线）web",map.get("machNo"),cashPayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        } else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }


    /*
     * @Description:支付请求（强在线）- 自主售卖机
     * @Author: lu
     * @Date: 2022/4/28 17:03
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse onlinePayB(Map<String, Object> map) {
        //逻辑，先写入菜品，再匹配现有的支付结构
        //deviceCode||aisleCode||goodsId||count 菜品备注 组装规则 设备号||货道号||商品ID||数量
        Result resultA = this.payConfigClientService.deviceInfo(map); //判断设备状态
        if(resultA.getCode() != 200){
            return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
        }
        List<MachMealDataVo> mealData = this.getMealData(map);
        this.redisUtil.set("weimi:"+map.get("companyID")+":"+ map.get("tradeNo"),JSON.toJSONString(map),86400L);     //将下单参数缓存起来,给机器用
        if(ObjectUtil.isEmpty(mealData)){
            log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）自助售卖机",map.get("machNo"),JSON.toJSONString(map),"无商品");
            return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
        }
        map.put("menuData",JSON.toJSONString(mealData));
        Integer type= (Integer) map.get("type");
        if (type==5 ||type==10){
            QrCodePayRequest qrCodePayRequest=new QrCodePayRequest();
            try {
                qrCodePayRequest.setMachNo(String.valueOf(map.get("machNo")));
                qrCodePayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                if (map.get("consType") !=null){
                    qrCodePayRequest.setConsType((Integer) map.get("consType"));
                }
                qrCodePayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
                qrCodePayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
                qrCodePayRequest.setAmount((Integer) map.get("amount"));

                try {
                    Object consState = map.get("consState");
                    if (consState != null) {
                        Integer cons = (Integer) consState;
                        qrCodePayRequest.setConsState(cons);
                        if ((cons == 3 || cons == 5 ) && map.get("menuData") != null) {
                            if(map.get("consDate") != null) qrCodePayRequest.setConsDate(String.valueOf(map.get("consDate")));
                            if(map.get("consMeal") != null) qrCodePayRequest.setConsMeal((Integer)map.get("consMeal"));
                            if(map.get("consPoint") != null) qrCodePayRequest.setConsPoint((Integer)map.get("consPoint"));
                            qrCodePayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                        }
                    }
                }catch (Exception exception){
                    log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）订餐1",map.get("machNo"),qrCodePayRequest,exception);
                }

            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）web",map.get("machNo"),qrCodePayRequest,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.qrCodePay(qrCodePayRequest);
            if (result.getCode()==200){
                //下单到微米
                this.payConfigClientService.shipment(map);
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","支付请求（强在线）web",map.get("machNo"),qrCodePayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else if (type==1 || type==4 || type==7 || type== 8 || type== 9 || type== 21  || type== 25){
            QrCardPayRequest qrCardPayRequest=new QrCardPayRequest();
            try {
                qrCardPayRequest.setMachNo(String.valueOf(map.get("machNo")));
                qrCardPayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                qrCardPayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
                qrCardPayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
                qrCardPayRequest.setAmount((Integer) map.get("amount"));
                if (map.get("consType") !=null){
                    qrCardPayRequest.setConsType((Integer) map.get("consType"));
                }
                if (type == 8){
                    if (map.get("face_token") !=null){
                        qrCardPayRequest.setFaceToken((String) map.get("face_token"));
                    }else{
                        return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
                    }
                }
                if (type == 9){
                    if (map.get("face_token") ==null || map.get("uId") ==null || map.get("verificationData") ==null ){
                        return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
                    }
                    qrCardPayRequest.setFaceToken((String) map.get("face_token"));
                    qrCardPayRequest.setUId((String) map.get("uId"));
                    qrCardPayRequest.setIotSignInfo((String) map.get("verificationData"));
                }
                try {
                    Object consState = map.get("consState");
                    if (consState != null) {
                        Integer cons = (Integer) consState;
                        qrCardPayRequest.setConsState(cons);
                        if ((cons == 3 || cons == 5 ) && map.get("menuData") != null) {
                            if(map.get("consDate") != null) qrCardPayRequest.setConsDate(String.valueOf(map.get("consDate")));
                            if(map.get("consMeal") != null) qrCardPayRequest.setConsMeal((Integer)map.get("consMeal"));
                            if(map.get("consPoint") != null) qrCardPayRequest.setConsPoint((Integer)map.get("consPoint"));
                            qrCardPayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                        }
                    }
                }catch (Exception exception){
                    log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）订餐1",map.get("machNo"),qrCardPayRequest,exception);
                }
                qrCardPayRequest.setType(type);
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）web",map.get("machNo"),qrCardPayRequest,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result = payoperFeignService.getPayCard(qrCardPayRequest);
            if (result.getCode()==200){
                //下单到微米
                this.payConfigClientService.shipment(map);
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","支付请求（强在线）web",map.get("machNo"),qrCardPayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else if ( type== 20 ){  //20 现金
            CashPayRequest cashPayRequest =new CashPayRequest();
            cashPayRequest.setMachNo(String.valueOf(map.get("machNo")));
            cashPayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
            cashPayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
            cashPayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
            cashPayRequest.setAmount((Integer) map.get("amount"));
            cashPayRequest.setType(type);
            try {
                Object consState = map.get("consState");
                if (consState != null) {
                    Integer cons = (Integer) consState;
                    cashPayRequest.setConsState(cons);
                    if ((cons == 3 || cons == 5 ) && map.get("menuData") != null) {
                        if(map.get("consDate") != null) cashPayRequest.setConsDate(String.valueOf(map.get("consDate")));
                        if(map.get("consMeal") != null) cashPayRequest.setConsMeal((Integer)map.get("consMeal"));
                        if(map.get("consPoint") != null) cashPayRequest.setConsPoint((Integer)map.get("consPoint"));
                        cashPayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                    }
                }
            }catch (Exception exception){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（强在线）订餐1",map.get("machNo"),cashPayRequest,exception);
            }
            Result result=payoperFeignService.cashPayDiches(cashPayRequest);
            if (result.getCode()==200){
                //下单到微米
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","支付请求（主扫）web",map.get("machNo"),cashPayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        } else if (type == 26) {
            //农行付款码支付
            StaticCodePayRequest staticCodePayRequest=new StaticCodePayRequest();
            try {
                staticCodePayRequest.setMachNo(String.valueOf(map.get("machNo")));
                staticCodePayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                if (map.get("consType") !=null){
                    staticCodePayRequest.setConsType((Integer) map.get("consType"));
                }
                staticCodePayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
                staticCodePayRequest.setAmount((Integer) map.get("amount"));
                staticCodePayRequest.setType(type);

                try {
                    Object consState = map.get("consState");
                    if (consState != null) {
                        Integer cons = (Integer) consState;
                        staticCodePayRequest.setConsState(cons);
                        if ((cons == 3 || cons == 5 ) && map.get("menuData") != null) {
//                            if(map.get("consDate") != null) staticCodePayRequest.setConsDate(String.valueOf(map.get("consDate")));
//                            if(map.get("consMeal") != null) staticCodePayRequest.setConsMeal((Integer)map.get("consMeal"));
//                            if(map.get("consPoint") != null) staticCodePayRequest.setConsPoint((Integer)map.get("consPoint"));
                            staticCodePayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                        }
                    }
                }catch (Exception exception){
                    log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（主扫）订餐1",map.get("machNo"),staticCodePayRequest,exception);
                }

            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","支付请求（主扫）web",map.get("machNo"),staticCodePayRequest,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.staticCodePay(staticCodePayRequest);
            if (result.getCode()==200){
                //下单到微米
//                this.payConfigClientService.shipment(map);
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","支付请求（主扫）web",map.get("machNo"),staticCodePayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        } else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }


    /*
     * @Description:强在线订单查询
     * @Author: lu 
     * @Date: 2022/5/19 14:19
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse onlineQuery(Map<String, Object> map) {
        Integer type= (Integer) map.get("type");
        if (type==5 ||type==10  || type==21){
            QrCodeQueryRequest request=new QrCodeQueryRequest();
            try {
                request.setMachNo(String.valueOf(map.get("machNo")));
                request.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                request.setTradeNo(String.valueOf(map.get("tradeNo")));
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","强在线订单查询 web",map.get("machNo"),request,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.qrCodeQuery(request);
            if (result.getCode()==200){
//                //下单到微米
//                String weimiKey = "weimi:"+map.get("companyID")+":"+ map.get("tradeNo");
//                Object weimiObject = this.redisUtil.get(weimiKey);
//                if(ObjectUtil.isNotEmpty(weimiObject)){
//                    Map<String,Object> map1 = JSON.parseObject((String) weimiObject);
//                    Result result1 = this.payConfigClientService.shipment(map1);
//                    if(result1.getCode() == 200){
//                        this.redisUtil.del(weimiKey);
//                    }
//                }
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","强在线订单查询 web",map.get("machNo"),request, result);
                if(result.getCode() == 3030){
                    return JsonResponse.error("3030",result.getMsg());
                }else {
                    return JsonResponse.error("3029",result.getMsg());
                }
//                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else if (type==4 || type==1 || type==7 || type==25){
            QrCodeQueryRequest request=new QrCodeQueryRequest();
            try {
                request.setMachNo(String.valueOf(map.get("machNo")));
                request.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                request.setTradeNo(String.valueOf(map.get("tradeNo")));
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","强在线订单查询 web",map.get("machNo"),request,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.onlinePayQuery(request);
            if (result.getCode()==200){
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","强在线订单查询 web",map.get("machNo"),request, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }

    /*
     * @Description:交易中撤单
     * @Author: lu 
     * @Date: 2022/5/19 14:34
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse cancelOrder(Map<String, Object> map) {
        Integer type= (Integer) map.get("type");
        if (type==3){
            QrCodeQueryRequest request=new QrCodeQueryRequest();
            try {
                request.setMachNo(String.valueOf(map.get("machNo")));
                request.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                request.setTradeNo(String.valueOf(map.get("tradeNo")));
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","交易中撤单 web",map.get("machNo"),request,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.qrCodeCancel(request);
            if (result.getCode()==200){
                return JsonResponse.success();
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","交易中撤单 web",map.get("machNo"),request, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }

    /*
     * @Description:设备交易号退款
     * @Author: lu 
     * @Date: 2022/5/19 14:37
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse refund(Map<String, Object> map) {
        Integer type= (Integer) map.get("tradeType");
        if (type==2 || type==1){
            QrCodeRefundRequest request=new QrCodeRefundRequest();
            try {
                request.setMachNo(String.valueOf(map.get("machNo")));
                request.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                request.setTradeNo(String.valueOf(map.get("tradeNo")));
                request.setOrigTradeNo(String.valueOf(map.get("origTradeNo")));
                Integer refundAmount= (Integer) map.get("refundAmount");
                request.setRefundAmount(Math.abs(refundAmount));
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","设备交易号退款 web",map.get("machNo"),request,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.qrCodeRefund(request);
            if (result.getCode()==200){
                return JsonResponse.success();
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","设备交易号退款 web",map.get("machNo"),request, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }

    /*
     * @Description:账单列表查询(BillList; )
     * @Author: lu 
     * @Date: 2022/5/19 15:08
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse billList(Map<String, Object> map) {
        Integer type= (Integer) map.get("tradeType");
        if (type==3){
            QrCodeBillListRequest request=new QrCodeBillListRequest();
            int pageIndex=0;
            try {
                pageIndex = (int) map.get("pageIndex");
                request.setMachNo(String.valueOf(map.get("machNo")));
                request.setCompanyID(Long.valueOf(map.get("companyID").toString()));
                request.setPageIndex(pageIndex);
                request.setSize(10);
                if(map.get("consState")!=null){
                    request.setConsState((Integer) map.get("consState"));
                }
                if(map.get("type")!=null){
                    request.setType((Integer) map.get("type"));
                }
                if(map.get("authCode")!=null){
                    request.setAuthCode((String) map.get("authCode"));
                }
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","账单列表查询 web",map.get("machNo"),request,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.machBillList(request);
            if (result.getCode()==200){
                Map<String,Object> reMap =new HashMap<>();
                JSONObject json= JSON.parseObject(JSON.toJSONString(result.getData()));
                int total=json.getInteger("total");
                int Status=total-(pageIndex*10)>0?1:0;
                reMap.put("Status",Status);
                reMap.put("orderData_s",json.get("orderData_s"));
                return JsonResponse.success(reMap);
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","账单列表查询 web",map.get("machNo"),request, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }

    /*
     * @Description:消费汇总查询
     * @Author: lu 
     * @Date: 2022/5/20 9:33
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse machQuery(Map<String, Object> map) {
        Integer type= (Integer) map.get("queryType");
        if (type==101){
            QrCodeMachDailySummaryRequest request=new QrCodeMachDailySummaryRequest();
            try {
                request.setMachNo(String.valueOf(map.get("machNo")));
                request.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                request.setQueryDate(String.valueOf(map.get("queryDate")));
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","消费汇总查询 web",map.get("machNo"),request,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.machDailySummary(request);
            if (result.getCode()==200){
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","消费汇总查询 web",map.get("machNo"),request, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }

    /*
     * @Description:余额查询
     * @Author: lu
     * @Date: 2022/6/29 16:22
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse Balance(Map<String, Object> map) {
        try {
            Object mode = map.get("mode");
            RespMachMessage changeWhiteListState = null;
            if (mode != null && (Integer) mode == 1) {
                changeWhiteListState = payoperFeignService.getBalancePhone(map);
            } else {
                changeWhiteListState = payoperFeignService.getBalance(map);
            }
            return JsonResponse.success(changeWhiteListState.getCode(),changeWhiteListState.getMsg(),changeWhiteListState.getData());
        }catch (Exception e){
            log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","余额查询",map.get("machNo"),map,e);
            return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
        }
    }

    /*
     * @Description:消费记录
     * @Author: lu 
     * @Date: 2022/7/5 15:49
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @Override
    public JsonResponse tradeRecord(Map<String, Object> map) {
        Integer type= (Integer) map.get("type");
        if(type == 7) type = 3;
        if (type==3 || type==1 || type==4 || type==5 || type==9 || type==25 || type==22){
            TradeRecordRequest request=new TradeRecordRequest();
            try {
                request.setMachNo(String.valueOf(map.get("machNo")));
                request.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                request.setTradeNo(String.valueOf(map.get("tradeNo")));
                request.setAmount((Integer) map.get("amount"));
                request.setTradeTime(String.valueOf(map.get("tradeTime")));
                if (map.get("consType") !=null){
                    request.setConsType((Integer) map.get("consType"));
                }
                request.setType(type);
                request.setLineSymbol((Integer) map.get("lineSymbol"));
                try {
                    String cardNum= String.valueOf(map.get("cardNum"));
                    request.setUserId(Long.valueOf(cardNum));
                }catch (Exception e){
                    log.error("人员异常 【{}】 【{}】 【{}】",request.getMachNo(),map,e);
                    request.setUserId(0l);
                }

                if (type == 8){
                    if (map.get("face_token") !=null){
                        request.setFaceToken((String) map.get("face_token"));
                    }else{
                        return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
                    }
                }
                if (type == 9){
                    if (map.get("face_token") ==null || map.get("uId") ==null || map.get("verificationData") ==null ){
                        return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
                    }
                    request.setFaceToken((String) map.get("face_token"));
                    request.setUId((String) map.get("uId"));
                    request.setVerificationData((String) map.get("verificationData"));
                }
                if (type == 22) {
                    if (map.get("uId") != null) {
                        request.setUId((String) map.get("uId"));
                    } else {
                        return JsonResponse.error(StateCode.RequiredNullCod, StateCode.RequiredNullMsg);
                    }
                    if (map.get("face_token") != null) {
                        request.setFaceToken((String) map.get("face_token"));
                    } else {
                        return JsonResponse.error(StateCode.RequiredNullCod, StateCode.RequiredNullMsg);
                    }
                }
                try {
                    if(map.get("menuData")!=null){
                        request.setMenuData(JSON.parseArray(JSON.toJSONString(map.get("menuData")), MachMealDataVo.class));
                    }
                }catch (Exception ee){
                    log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,菜品添加异常:【{}】","消费记录",map.get("machNo"),request,ee);
                }
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","消费记录",map.get("machNo"),request,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result =null;
            if(type==9){
                result = payoperFeignService.aliOfflinePay(request);
            }else{
                Integer comId = (Integer) map.get("companyID");
//                if (comId == 47 || comId == 584 || comId == 651 || comId == 52 || comId == 79 ) {
                    result = payoperFeignService.saveXfRecordD(request);
//                } else {
//                    result = payoperFeignService.saveXfRecord(request);
//                }
            }
            if (result.getCode()==200){
                Map<String,Object> reMap=new HashMap<>();
                reMap.put("recordId",map.get("recordId"));
                return JsonResponse.success(reMap);
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","消费记录",map.get("machNo"),request, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }

    //3.34 充值强在线请求（0x0104）
    @Override
    public JsonResponse deposit(Map<String, Object> map) {
        Integer type= (Integer) map.get("type");
        if (type==1 || type==4 || type==7){
            RechargeCardRequest qrCardPayRequest=new RechargeCardRequest();
            try {
                qrCardPayRequest.setMachNo(String.valueOf(map.get("machNo")));
                qrCardPayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                qrCardPayRequest.setCardNum(String.valueOf(map.get("cardNum")));
                qrCardPayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
                qrCardPayRequest.setAmount((Integer) map.get("amount"));
                qrCardPayRequest.setType(type);
            }catch (Exception e){
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","充值强在线请求",map.get("machNo"),qrCardPayRequest,e);
                return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
            }
            Result result=payoperFeignService.onlineDeposit(qrCardPayRequest);
            if (result.getCode()==200){
                return JsonResponse.success(result.getData());
            }else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","充值强在线请求",map.get("machNo"),qrCardPayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
            }
        }else {
            return JsonResponse.error(StateCode.PayTypeCod,StateCode.PayTypeMsg);
        }
    }

    @Override
    public JsonResponse WXAuthinfo(Map<String, Object> map) {
        AuthinfoRequest qrCardPayRequest=new AuthinfoRequest();
        try {
            qrCardPayRequest.setMachNo(String.valueOf(map.get("machNo")));
            qrCardPayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
            qrCardPayRequest.setDeviceId(String.valueOf(map.get("device_id")));
            qrCardPayRequest.setRawdata(String.valueOf(map.get("rawdata")));
        }catch (Exception e){
            log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】","获取微信人脸授权信息",map.get("machNo"),qrCardPayRequest,e);
            return JsonResponse.error(StateCode.RequiredNullCod,StateCode.RequiredNullMsg);
        }
        Result result=payoperFeignService.WXAuthinfo(qrCardPayRequest);
        if (result.getCode()==200){
            return JsonResponse.success(result.getData());
        }else {
            log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】","获取微信人脸授权信息",map.get("machNo"),qrCardPayRequest, result);
            return JsonResponse.error(String.valueOf(result.getCode()),result.getMsg());
        }
    }

    @Override
    public JsonResponse OnlinePayRepair(Map<String, Object> map) {
        Integer type = (Integer) map.get("type");
        if (type == 5 || type == 10) {
            QrCodePayRequest qrCodePayRequest = new QrCodePayRequest();
            try {
                qrCodePayRequest.setMachNo(String.valueOf(map.get("machNo")));
                qrCodePayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                if (map.get("consType") != null) {
                    qrCodePayRequest.setConsType((Integer) map.get("consType"));
                }
                qrCodePayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
                qrCodePayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
                qrCodePayRequest.setAmount((Integer) map.get("amount"));

                try {
                    Object consState = map.get("consState");
                    if (consState != null) {
                        Integer cons = (Integer) consState;
                        qrCodePayRequest.setConsState(cons);
                        if ((cons == 3 || cons == 5) && map.get("menuData") != null) {
                            if (map.get("consDate") != null)
                                qrCodePayRequest.setConsDate(String.valueOf(map.get("consDate")));
                            if (map.get("consMeal") != null)
                                qrCodePayRequest.setConsMeal((Integer) map.get("consMeal"));
                            if (map.get("consPoint") != null)
                                qrCodePayRequest.setConsPoint((Integer) map.get("consPoint"));
                            qrCodePayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                        }
                    }
                } catch (Exception exception) {
                    log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线）订餐1", map.get("machNo"), qrCodePayRequest, exception);
                }

            } catch (Exception e) {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线）web", map.get("machNo"), qrCodePayRequest, e);
                return JsonResponse.error(StateCode.RequiredNullCod, StateCode.RequiredNullMsg);
            }
            Result result = payoperFeignService.qrCodePay(qrCodePayRequest);
            if (result.getCode() == 200) {
                return JsonResponse.success(result.getData());
            } else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】", "支付请求（强在线）web", map.get("machNo"), qrCodePayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()), result.getMsg());
            }
        } else if (type == 1 || type == 4 || type == 7 || type == 8 || type == 9 || type == 21 || type == 25) {

            OnlineRepairQueryRequest onlineRepairQueryRequest = new OnlineRepairQueryRequest();
            onlineRepairQueryRequest.setMachNo(String.valueOf(map.get("machNo")));
            onlineRepairQueryRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
            onlineRepairQueryRequest.setType(type);
            onlineRepairQueryRequest.setAuthCode(String.valueOf(map.get("auth_code")));
            RespMachMessage respMachMessage = payoperFeignService.onlineRepairQuery(onlineRepairQueryRequest);
            if (respMachMessage.getCode().equals("0000")) {
                //成功
                Map<String, Object> mapResult = new HashMap<>();
                mapResult.put("discount", 0);
                mapResult.put("payAmount",(Integer) map.get("amount"));
                Map<String, Object> mapAccountInf = new HashMap<>();
                mapAccountInf.put("name", "");
                mapAccountInf.put("money", 0l);
                mapAccountInf.put("allowance", 0l);
                mapAccountInf.put("cardtype", 0);
                mapResult.put("accountInf", mapAccountInf);
                mapResult.put("pickupNum", "0");
                mapResult.put("orderTime", new Date());
                mapResult.put("repairList", respMachMessage.getData());
                return JsonResponse.error(StateCode.WaitPayCode, StateCode.WaitPayMsg,mapResult);
            }

            QrCardPayRequest qrCardPayRequest = new QrCardPayRequest();
            try {
                qrCardPayRequest.setMachNo(String.valueOf(map.get("machNo")));
                qrCardPayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
                qrCardPayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
                qrCardPayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
                qrCardPayRequest.setAmount((Integer) map.get("amount"));
                if (map.get("consType") != null) {
                    qrCardPayRequest.setConsType((Integer) map.get("consType"));
                }
                if (type == 8) {
                    if (map.get("face_token") != null) {
                        qrCardPayRequest.setFaceToken((String) map.get("face_token"));
                    } else {
                        return JsonResponse.error(StateCode.RequiredNullCod, StateCode.RequiredNullMsg);
                    }
                }
                if (type == 9) {
                    if (map.get("face_token") == null || map.get("uId") == null || map.get("verificationData") == null) {
                        return JsonResponse.error(StateCode.RequiredNullCod, StateCode.RequiredNullMsg);
                    }
                    qrCardPayRequest.setFaceToken((String) map.get("face_token"));
                    qrCardPayRequest.setUId((String) map.get("uId"));
                    qrCardPayRequest.setIotSignInfo((String) map.get("verificationData"));
                }
                try {
                    Object consState = map.get("consState");
                    if (consState != null) {
                        Integer cons = (Integer) consState;
                        qrCardPayRequest.setConsState(cons);
                        if ((cons == 3 || cons == 5) && map.get("menuData") != null) {
                            if (map.get("consDate") != null)
                                qrCardPayRequest.setConsDate(String.valueOf(map.get("consDate")));
                            if (map.get("consMeal") != null)
                                qrCardPayRequest.setConsMeal((Integer) map.get("consMeal"));
                            if (map.get("consPoint") != null)
                                qrCardPayRequest.setConsPoint((Integer) map.get("consPoint"));
                            qrCardPayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                        }
                    }
                } catch (Exception exception) {
                    log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线）订餐1", map.get("machNo"), qrCardPayRequest, exception);
                }
                qrCardPayRequest.setType(type);
            } catch (Exception e) {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线）web", map.get("machNo"), qrCardPayRequest, e);
                return JsonResponse.error(StateCode.RequiredNullCod, StateCode.RequiredNullMsg);
            }
            Result result = payoperFeignService.getPayCard(qrCardPayRequest);
            if (result.getCode() == 200) {
                return JsonResponse.success(result.getData());
            } else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】", "支付请求（强在线）web", map.get("machNo"), qrCardPayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()), result.getMsg());
            }
        } else if (type == 20) {  //20 现金
            CashPayRequest cashPayRequest = new CashPayRequest();
            cashPayRequest.setMachNo(String.valueOf(map.get("machNo")));
            cashPayRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
            cashPayRequest.setAuthCode(String.valueOf(map.get("auth_code")));
            cashPayRequest.setTradeNo(String.valueOf(map.get("tradeNo")));
            cashPayRequest.setAmount((Integer) map.get("amount"));
            cashPayRequest.setType(type);
            try {
                Object consState = map.get("consState");
                if (consState != null) {
                    Integer cons = (Integer) consState;
                    cashPayRequest.setConsState(cons);
                    if ((cons == 3 || cons == 5) && map.get("menuData") != null) {
                        if (map.get("consDate") != null)
                            cashPayRequest.setConsDate(String.valueOf(map.get("consDate")));
                        if (map.get("consMeal") != null) cashPayRequest.setConsMeal((Integer) map.get("consMeal"));
                        if (map.get("consPoint") != null) cashPayRequest.setConsPoint((Integer) map.get("consPoint"));
                        cashPayRequest.setMealData(JSON.parseArray((String) map.get("menuData"), MachMealDataVo.class));
                    }
                }
            } catch (Exception exception) {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线）订餐1", map.get("machNo"), cashPayRequest, exception);
            }
            Result result = payoperFeignService.cashPayDiches(cashPayRequest);
            if (result.getCode() == 200) {
                return JsonResponse.success(result.getData());
            } else {
                log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,返回:【{}】", "支付请求（强在线）web", map.get("machNo"), cashPayRequest, result);
                return JsonResponse.error(String.valueOf(result.getCode()), result.getMsg());
            }
        } else {
            return JsonResponse.error(StateCode.PayTypeCod, StateCode.PayTypeMsg);
        }
    }

    @Override
    public JsonResponse PayRepair(Map<String, Object> map) {
        try {

            Long comId = Long.valueOf(map.get("companyID").toString());
            Long backId = Long.valueOf(map.get("backId").toString());
            BackPayRequest backPayRequest = new BackPayRequest();

            backPayRequest.setCompanyId(comId);
            backPayRequest.setBackId(backId);
            backPayRequest.setMachNo(String.valueOf(map.get("machNo")));
            backPayRequest.setTradeNo("BJ" + new Date().getTime() + comId + "N" + 00 + "M" + RandomUtil.generateNumber(8));
            Result result = payoperFeignService.backPay(backPayRequest);
            if (result.getCode() == 200) {
                return JsonResponse.success(result.getData());
            } else {
                return JsonResponse.error(String.valueOf(result.getCode()), result.getMsg());
            }


        } catch (Exception exception) {
            log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线-补缴订单）", map.get("machNo"), map, exception);
            return JsonResponse.error(StateCode.PayTypeCod, StateCode.PayTypeMsg);
        }
    }

    @Override
    public JsonResponse RepairQuery(Map<String, Object> map) {
        try {
            Integer type = (Integer) map.get("type");
            OnlineRepairQueryRequest onlineRepairQueryRequest = new OnlineRepairQueryRequest();
            onlineRepairQueryRequest.setMachNo(String.valueOf(map.get("machNo")));
            onlineRepairQueryRequest.setCompanyId(Long.valueOf(map.get("companyID").toString()));
            onlineRepairQueryRequest.setType(type);
            onlineRepairQueryRequest.setAuthCode(String.valueOf(map.get("authCode")));
            RespMachMessage respMachMessage = payoperFeignService.onlineRepairQuery(onlineRepairQueryRequest);
            if (respMachMessage.getCode().equals("0000")) {
                Map<String, Object> mapResult = new HashMap<>();
                mapResult.put("repairList", respMachMessage.getData());
                return JsonResponse.success(mapResult);
            }
            return JsonResponse.success();
        } catch (Exception exception) {
            log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线-补缴订单）", map.get("machNo"), map, exception);
            return JsonResponse.error(StateCode.PayTypeCod, StateCode.PayTypeMsg);
        }
    }

    @Override
    public JsonResponse RegisterPalm(Map<String, Object> map) {
        try {
            Long comId = Long.valueOf(map.get("companyID").toString());

            RegisterPalmRequest registerPalmRequest = JSON.parseObject(JSON.toJSONString(map), RegisterPalmRequest.class);
            registerPalmRequest.setComId(comId);

            Result result = humanClientService.registerPalm(registerPalmRequest);

            if (result.getCode() == 200) {
                return JsonResponse.success(result.getData());
            } else {
                return JsonResponse.error(String.valueOf(result.getCode()), result.getMsg());
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线-掌纹注册）", map.get("machNo"), map, exception);
            return JsonResponse.error(StateCode.UnknownExceptionCode, StateCode.UnknownExceptionMsg);

        }
    }

    @Override
    public JsonResponse personQuery(Map<String, Object> map) {
        try {
            Long comId = Long.valueOf(map.get("companyID").toString());

            PersonQueryRequest personQueryRequest = JSON.parseObject(JSON.toJSONString(map), PersonQueryRequest.class);
            personQueryRequest.setComId(comId);

            Result result = humanClientService.getPersonInfoByPalm(personQueryRequest);

            if (result.getCode() == 200) {
                return JsonResponse.success(result.getData());
            } else {
                return JsonResponse.error(String.valueOf(result.getCode()), result.getMsg());
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            log.info("请求方式:【{}】,机器号:【{}】,请求参数:【{}】,异常:【{}】", "支付请求（强在线-查询用户）", map.get("machNo"), map, exception);
            return JsonResponse.error(StateCode.UnknownExceptionCode, StateCode.UnknownExceptionMsg);
        }
    }

    @Override
    public JsonResponse consTypeConfig(Map<String, Object> map) {
        try {
            Long comId = Long.valueOf(map.get("companyID").toString());
            String machNo = String.valueOf(map.get("machNo"));
            Long pId = Long.valueOf(map.get("pId").toString());

            ConsTypeConfigRequest request =new ConsTypeConfigRequest();
            request.setComId(comId);
            request.setMachNo(machNo);
            request.setPId(pId);

            Result result = payoperFeignService.consTypeConfig(request);

            if (result.getCode() == 200) {
                return JsonResponse.success(result.getData());
            } else {
                return JsonResponse.error(String.valueOf(result.getCode()), result.getMsg());
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            log.info("请求方式:【{}】, nHD5SU7K 机器号:【{}】,请求参数:【{}】,异常:【{}】", "consTypeConfig", map.get("machNo"), map, exception);
            return JsonResponse.error(StateCode.UnknownExceptionCode, StateCode.UnknownExceptionMsg);
        }
    }

    //组合数据
    private List<MachMealDataVo> getMealData(Map<String, Object> map){
        List<MachMealDataVo> mealDataVoList = new ArrayList<>();
        if(ObjectUtil.isEmpty(map.get("aisleGoodsList"))){
            return mealDataVoList;
        }
        JSONObject jsonObject1 =new JSONObject();
        jsonObject1.put("comId",map.get("companyID"));
        jsonObject1.put("mqttDeviceNo",map.get("mqttDeviceNo"));
        Result result = this.payConfigClientService.iotDeviceDetail(jsonObject1);
        EntityMqttDevice entityMqttDevice = JSON.parseObject(JSON.toJSONString(result.getData()),EntityMqttDevice.class);
        //获取商户信息
        List<JSONObject> list = new ArrayList<>();
        try {
            String unescapedJson = String.valueOf(map.get("aisleGoodsList")).replaceAll("\\\\", "");
            list = JSON.parseArray(unescapedJson,JSONObject.class);
            map.put("aisleGoodsList",list);
        }catch (Exception exception){
            return null;
        }
        list.forEach(jsonObject -> {
            jsonObject.put("aisleCode",jsonObject.getString("code"));
            int count = ObjectUtil.isEmpty(jsonObject.getInteger("count")) || jsonObject.getInteger("count") < 1 ?1:jsonObject.getInteger("count");
            for (int i = 0; i < count; i++) {
                String dishesCode = cn.hutool.core.util.RandomUtil.randomString(10);
                JSONObject jsonObjectA = new JSONObject();
                jsonObjectA.put("comId",map.get("companyID"));
                jsonObjectA.put("merchId",entityMqttDevice.getMerchId());
                jsonObjectA.put("dishesName",jsonObject.getString("code") + "||" + jsonObject.getString("goodsId") + "||"+dishesCode);
                jsonObjectA.put("dishesCode", dishesCode);
                jsonObjectA.put("dishesClassId",entityMqttDevice.getDishesClassId());
                jsonObjectA.put("status","1");
                Result result1 = this.payConfigClientService.newDishes(jsonObjectA);
                EntityDishesInfo entityDishesInfo = JSON.parseObject(JSON.toJSONString(result1.getData()),EntityDishesInfo.class);
                if(ObjectUtil.isEmpty(entityDishesInfo)){
                    log.info("获取菜品分类错误,请建立自助机,参数【{}】,【{}】",JSON.toJSONString(map),JSON.toJSONString(entityDishesInfo));
                    return;
                }
                MachMealDataVo machMealDataVo = new MachMealDataVo();
                machMealDataVo.setDishesId(entityDishesInfo.getDishesId());
                machMealDataVo.setDishesName(entityDishesInfo.getDishesName());
                machMealDataVo.setNum(1);
                machMealDataVo.setPriceMode(22);
                machMealDataVo.setUnitPrice(jsonObject.getInteger("price"));
                machMealDataVo.setPrice(jsonObject.getInteger("price"));
                machMealDataVo.setEtime(DateUtil.format(new Date(),"yyyyMMddHHmmss"));
                mealDataVoList.add(machMealDataVo);
            }

        });
        return mealDataVoList;
    }
}
